package cn.hotel.service;

import cn.hotel.mapper.OrderFormMapper;
import cn.hotel.mapper.OrderFormMapperImpl;
import cn.hotel.pojo.HouseType;
import cn.hotel.pojo.Member;
import cn.hotel.pojo.OrderManagement;
import cn.hotel.pojo.RoomKeeper;
import cn.hotel.utlis.ResultMapUtil;

import java.util.Date;
import java.util.List;
import java.util.Map;

public class OrderFormServiceImpl implements OrderFormService {
    private OrderFormMapper orderFormMapper = new OrderFormMapperImpl();

    //展示房型
    @Override
    public List<HouseType> show() {
        List<HouseType> houseTypeList = orderFormMapper.show();
        return orderFormMapper == null ? null : houseTypeList;
    }

    //多少条数据
    @Override
    public int count(int typeId,int condition,int roomNumber,String name) {
        int count = orderFormMapper.count(typeId,condition,roomNumber,name);
        return count;
    }

    //展示所以信息 根据房型,状态,房间号,姓名
    @Override
    public List<OrderManagement> seek(int typeId,int condition,int roomNumber,String name, int index, int page) {
        int indexId = (index - 1) * page;
        List<OrderManagement> seekList = orderFormMapper.seek(typeId,condition,roomNumber,name,indexId,page);
        return seekList;
    }

    //删除订单
    @Override
    public Map<String, Object> delete(Long id) {
        int delete = orderFormMapper.delete(id);
        try {
            if (delete > 0){
                Map<String,Object> resultMap = ResultMapUtil.success("删除成功");
                resultMap.put("data",delete);
                return resultMap;
            }else {
                return ResultMapUtil.error("删除失败");
            }
        }catch (Exception e){
            e.printStackTrace();
            return ResultMapUtil.expection();
        }
    }

    //更新退房时间 根据房间号
    @Override
    public Map<String, Object> setCheckOutDate(int roomNumber) {
        int outDate = orderFormMapper.setCheckOutDate(roomNumber);
        try {
            if (outDate > 0){
                Map<String,Object> outDateMap = ResultMapUtil.success("更新成功!");
                outDateMap.put("data",outDate);
                return outDateMap;
            }else {
                return ResultMapUtil.error("更新失败!");
            }
        }catch (Exception e){
            e.printStackTrace();
            return ResultMapUtil.expection();
        }
    }

    //根据房号修改状态
    @Override
    public int setState(int condition, int roomNumber) {
        int amend = orderFormMapper.setState(condition,roomNumber);
        return amend;
    }

    //新增订单
    @Override
    public int addClient(OrderManagement orderManagement) {
        int result = orderFormMapper.addClient(orderManagement);
        return result;
    }

    //查空余房间 根据房间类型
    @Override
    public List<RoomKeeper> roomRates(int houseTypeId) {
        List<RoomKeeper> roomKeeperList = orderFormMapper.roomRates(houseTypeId);
        return roomKeeperList;
    }

    //查房间价格 根据房间类型
    @Override
    public HouseType roomPrice(int houseTypeId) {
        HouseType houseType = orderFormMapper.roomPrice(houseTypeId);
        return houseType;
    }

    //根据手机号验证手机号是否已存在
    @Override
    public int phoneVerify(String mobilePhone) {
        int count = orderFormMapper.phoneVerify(mobilePhone);
        return count;
    }

    //根据身份证号验证身份证号是否已存在
    @Override
    public int idCardVerify(String identityCard) {
        int count = orderFormMapper.idCardVerify(identityCard);
        return count;
    }

    //查询指定信息 根据房间号
    @Override
    public OrderManagement check(int roomNumber) {
        OrderManagement orderManagement = orderFormMapper.check(roomNumber);
        return orderManagement;
    }

    //修改入住信息 根据房间id
    @Override
    public Map<String, Object> revamp(OrderManagement orderManagement) {
        int up = orderFormMapper.revamp(orderManagement);
        try {
            if (up > 0){
                Map<String,Object> revampMap = ResultMapUtil.success("修改成功!");
                revampMap.put("data",up);
                return revampMap;
            }else {
                return ResultMapUtil.error("修改失败!");
            }
        }catch (Exception e){
            e.printStackTrace();
            return ResultMapUtil.expection();
        }
    }

    //会员验证
    @Override
    public Member vip(String mobilePhone) {
        return orderFormMapper.vip(mobilePhone);
    }
}